package com.mv.controller;

import com.mv.pojo.Movie;
import com.mv.service.MovieService;
import com.mv.vo.PageResult;
import com.mv.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/mv")
public class MovieController {
    @Autowired
    private MovieService movieService;
    /*获取电影销售量*/
    @GetMapping("/movie/getMovieCount")
    public SysResult getCount(){
        Integer count=movieService.getCount();
        return SysResult.success(count);
    }
    /*根据id查询电影信息*/
    @GetMapping("/movie/getMovie")
    public SysResult getMovie(Integer id){
        Movie movie=movieService.getMovie(id);
        return SysResult.success(movie);
    }
    /*获取电影分页数据*/
    @GetMapping("/movie/getMovieListByPage")
    public SysResult getMovieListByPage(PageResult pageResult){
        pageResult= movieService.getMovieListByPage(pageResult);
        return SysResult.success(pageResult);
    }
    /*获取所有电影信息*/
    @GetMapping("/movie/getMovieList")
    public SysResult getMovieList(){
        List<Movie> movieList=movieService.getMovieList();
        return SysResult.success(movieList);
    }
    /*1.添加电影*/
    @PostMapping("/movie/add")
    public SysResult addCard(@RequestBody Movie movie){
        movieService.addMovie(movie);
        return SysResult.success();
    }
    /*2.删除电影*/
    @DeleteMapping("/movie/delete")
    public SysResult update(Integer id){
        movieService.deleteMovie(id);
        return SysResult.success();
    }
    /*3.更新电影信息*/
    @PutMapping("/movie/updateMovie")
    public SysResult update(@RequestBody Movie movie){
        movieService.updateMovie(movie);
        return SysResult.success();
    }
}
